<template>
  <div>
    <el-descriptions title="我的信息" direction="vertical" :column="4" border>
      <el-descriptions-item label="用户名">{{ this.form.name }}</el-descriptions-item>
      <el-descriptions-item label="姓名">{{ this.form.username }}</el-descriptions-item>
      <el-descriptions-item label="学号">{{ this.form.studentNo }}</el-descriptions-item>
      <el-descriptions-item label="当前余额">{{ this.form.money }}</el-descriptions-item>
    </el-descriptions>

    <!-- 点击"充值"按钮时，显示嵌套表格的"弹窗" -->
    <el-dialog title="在线充值(模拟)" v-model="dialogFormVisible" width="30%">
      <el-form>
        <el-form-item label="充值金额" label-width="80px">
          <el-input v-model="money" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="支付方式" label-width="80px">
          <el-select v-model="value" placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="handle_recharge">确 定</el-button>
      </div>
    </el-dialog>

    <div style="margin-top: 20px;text-align: center;">
      <el-button style="color: white;background-color: rgb(128, 0, 128)" size="medium" @click="dialogFormVisible = true" round>
        <el-icon><Coin /></el-icon>
        <span>余 额 充 值</span>
      </el-button>
    </div>
  </div>
</template>


<script>
import request from "@/utils/request";
import { Coin } from '@element-plus/icons-vue'

export default {
  components: {
    Coin
  },
  data() {
    return {
      username: localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")) : {},
      form: {},
      dialogFormVisible: false,
      money: 0,
      // 级联选择器
      options: [
        { value: '选项1', label: '微信' },
        { value: '选项2', label: '支付宝' },
        { value: '选项3', label: '银行卡' },
        { value: '选项4', label: '白嫖' }
      ],
      value: ''
    };
  },
  created() {
    this.load();
  },
  methods: {
    load() {
      request.get("/client/user/person", {
        params: {
          name: this.username
        }
      }).then(res => {
        this.form = res.content;
      });
    },
    handle_recharge() {
      if (this.value === '') {
        this.$message.info("请选择支付方式.");
        return;
      }
      request.get("/client/user/recharge", {
        params: {
          name: this.username,
          money: this.money
        }
      }).then(res => {
        if (res.success) {
          this.load();
          this.$message.success(res.message);
          this.dialogFormVisible = false;
        } else {
          this.$message.error(res.message);
        }
      });
    }
  }
};
</script>